<template>
    <uxt-page :title="title">
        <uxt-bar-group title="设置">
            <uxt-single-selector-bar
                title="类型"
                :options="types"
                v-model="type"
            ></uxt-single-selector-bar>
            <uxt-bar title="禁用" desc="disabled">
                <template slot="right">
                    <uxt-switch v-model="disabled" radius size="sm"></uxt-switch>
                </template>
            </uxt-bar>
        </uxt-bar-group>
        <uxt-bar-group title="事件">
            <template slot="right">
                <text @click="events = ''">清空</text>
            </template>
            <view
                class="padding bg-white"
                v-html="events"
                style="height: 200rpx; overflow-y: auto;"
            ></view>
        </uxt-bar-group>
        <uxt-bar-group title="展示">
            <view class="padding bg-white text-center">
                <uxt-picker
                    v-model="value[type]"
                    :options="options[type]"
                    :disabled="disabled"
                    @change="handleEvent('change', $event)"
                    @cancel="handleEvent('cancel', $event)"
                >
                    <view class="bg-theme round padding text-center">{{ `${types[type]}(${value[type]})` }}</view>
                </uxt-picker>
            </view>
        </uxt-bar-group>
        <uxt-bar-group title="滑选栏">
            <uxt-bar title="盒模式" desc="box">
                <template slot="right">
                    <block v-if="box">
                        圆角：
                        <uxt-radio-group v-model="radius" size="sm" type="btn">
                            <uxt-radio label="无" value=""></uxt-radio>
                            <uxt-radio
                                classes="margin-lr-sm"
                                label="小圆角"
                                value="radius"
                            ></uxt-radio>
                            <uxt-radio
                                classes="margin-right-sm"
                                label="大圆角"
                                value="round"
                            ></uxt-radio>
                        </uxt-radio-group>
                    </block>
                    盒模式：
                    <uxt-switch v-model="box" round size="sm" @change="radius = ''"></uxt-switch>
                </template>
            </uxt-bar>
            <uxt-picker-bar
                title="滑选栏"
                v-model="value[type]"
                :options="options[type]"
                :box="box"
                :disabled="disabled"
                :round="radius === 'round'"
                :radius="radius === 'radius'"
                @change="handleEvent('change', $event)"
                @cancel="handleEvent('cancel', $event)"
            ></uxt-picker-bar>
        </uxt-bar-group>
    </uxt-page>
</template>

<script>
import uxtBarGroup from '@xtcoder/uxt/components/uxt-bar-group.vue'
import uxtBar from '@xtcoder/uxt/components/uxt-bar.vue'
import uxtRadioGroup from '@xtcoder/uxt/components/uxt-radio-group.vue'
import uxtRadio from '@xtcoder/uxt/components/uxt-radio.vue'
import uxtSwitch from '@xtcoder/uxt/components/uxt-switch.vue'
import uxtPicker from '@xtcoder/uxt/components/uxt-picker.vue'
import uxtPickerBar from '@xtcoder/uxt/components/uxt-picker-bar.vue'
import uxtSingleSelectorBar from '@xtcoder/uxt/components/uxt-single-selector-bar.vue'

export default {
    components: {
        uxtBarGroup,
        uxtBar,
        uxtRadioGroup,
        uxtRadio,
        uxtSwitch,
        uxtPicker,
        uxtPickerBar,
        uxtSingleSelectorBar
    },
    data() {
        return {
            title: '滑选器',
            types: ['单选', '多选', '联动'],
            type: 0,
            value: [-1, [1,1], [1,1,1]],
            options: [
                ['选项1', '选项2', '选项3', '选项4'],
                [
                    ['选项11', '选项12', '选项13', '选项14'],
                    ['选项21', '选项22', '选项23', '选项24']
                ],
                [
                    ['广东省', '江西省'],
                    [['广州市', '深圳市'], ['南昌市', '吉安市']],
                    [
                        [['天河区', '番禹区'], ['福田区', '龙岗区']],
                        [['东湖区', '西湖区'], ['吉州区', '吉安县']]
                    ]
                ]
            ],
            disabled: false,
            box: false,
            radius: '',
            events: ''
        }
    },
    methods: {
        handleEvent(type, e) {
            this.events += `@${type}${e !== undefined ? `(${JSON.stringify(e)})` : ''}<br />`
        }
    }
}
</script>

<style lang="scss" scoped></style>
